package me.wsj.fengyun.ui.activity

import android.content.Context
import android.content.Intent
import android.quickapp.windrain.R
import android.quickapp.windrain.databinding.ActivityWebBinding
import android.text.TextUtils
import me.wsj.fengyun.ui.base.BaseActivity
import me.wsj.fengyun.utils.H5Utils

class WebActivity : BaseActivity<ActivityWebBinding>() {


    private var mTitle: String? = null
    private var mUrl: String? = null

    companion object {

        fun launch(context: Context?, url: String?, titleStr: String?) {
            if (context != null && url != null) {
                //标题
                var title = titleStr
                if (TextUtils.isEmpty(title)) {
                    if (TextUtils.equals(url, H5Utils.H5_PRIVATE)) {
                        title = context.getString(R.string.regular_policy_simple)

                    } else if (TextUtils.equals(url, H5Utils.H5_PROTECT)) {
                        title = context.getString(R.string.regular_protocal_simple)
                    }
                }
                val intent = Intent()
                intent.setClass(context, WebActivity::class.java)
                intent.putExtra("key_url", url)
                intent.putExtra("key_title", title)
                context.startActivity(intent)
            }
        }
    }


    override fun bindView(): ActivityWebBinding {
        return ActivityWebBinding.inflate(layoutInflater)
    }

    override fun prepareData(intent: Intent?) {
        //初始化参数
        mUrl = intent?.getStringExtra("key_url")
        mTitle = intent?.getStringExtra("key_title")
    }

    override fun initView() {
        if (mTitle == null) {
            mTitle = ""
        }
        setTitle(mTitle)

        mUrl?.let { mBinding.webView.loadUrl(it) }

    }

    override fun initEvent() {

    }

    override fun initData() {

    }
}